Skip to content

Avoid strong reference reader count overflow#131

Open
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix-strong-reference-reader-overflow
Open

Avoid strong reference reader count overflow#131
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix-strong-reference-reader-overflow

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • Prevent atomic strong-reference reader counts from wrapping at capacity.
  • Replace masking/assert-only reader count encoding with checked preconditions.
  • Add a checked reader increment path that returns nil when the reader counter is full, causing _startLoading to reload and retry instead of publishing a wrapped count.
  • Add a focused regression test using a tiny injected reader mask through an underscored testing SPI.

Why

The strong-reference storage reserves a small reader-count field inside DoubleWord and previously incremented it with wrapping arithmetic. If enough readers entered concurrently, the count could wrap and make the storage appear to have fewer active readers than it actually did.

Testing

  • swift build passes locally.
  • swift test --filter StrongReferenceRace.testReaderCountDoesNotWrapAtCapacity could not run locally because this Swift toolchain cannot import XCTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant